<script>
  function makePromise(flag, value) {
    return flag ? Promise.resolve(value) : Promise.reject(value)
  }
  async function makePromise(flag, value) {
    if (flag) {
      return value
    } else {
      throw value
    }
  }

  function fn(flag, value) {
    if (flag) {
      return value
    } else {
      throw value
    }
  }

  const delay = (ms) =>
    new Promise((resolve, reject) => {
      setTimeout(resolve, ms)
    })
  function makeDelayPromise(ms, flag, value) {
    return delay(ms).then(() => {
      if (flag) {
        return value
      } else {
        throw value
      }
    })
  }
  async function makeDelayPromise(ms, flag, value) {
    await delay(ms)
    if (flag) {
      return value
    } else {
      throw value
    }
  }

  function processData(data) {
    var promise = new Promise(function (resolve, reject) {
      setTimeout(function () {
        resolve(data.value)
      }, Math.random() * 1000 + 500)
    })
    return promise
  }

  var data = [{ value: '奔' }, { value: '波' }, { value: '霸儿' }]

  var processed = []

  data.forEach(function (elem) {
    processed.push(processData(elem))
  })

  Promise.all(processed).then(function (response) {
    console.log(response) // ？？？
  })
</script>
